package gui;

import net.BackClient;
import net.ReceiveInformation;
import util.Protocol;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;

public class AddFriendUI extends JFrame {

    BackClient backClient = new BackClient();
    Protocol protocol = new Protocol();
    ReceiveInformation information = new ReceiveInformation();
    Thread thread = new Thread(new ReceiveInformation());
    String nickname;
    private JPanel contentPane;
    private JTextField textField;

    public AddFriendUI() {
        thread.start();
        information.addThisWindows("addFriendUI", this);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 355, 210);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JLabel label = new JLabel("\u597D\u53CB\u6DFB\u52A0");
        label.setFont(new Font("宋体", Font.BOLD, 15));
        label.setBounds(141, 10, 128, 15);
        contentPane.add(label);

        JLabel label_1 = new JLabel("\u597D\u53CB\u6635\u79F0\uFF1A");
        label_1.setBounds(81, 84, 73, 15);
        contentPane.add(label_1);

        textField = new JTextField();
        textField.setBounds(141, 81, 103, 21);
        contentPane.add(textField);
        textField.setColumns(10);

        JButton okButton = new JButton("\u786E\u5B9A");
        okButton.addActionListener(arg0 -> {
            String friendID = textField.getText();
            String finalMessage = protocol.getAddFriendMessage(nickname, friendID);
            backClient.SendMassage(finalMessage);
        });
        okButton.setBounds(264, 79, 73, 25);
        contentPane.add(okButton);

        JButton backButton = new JButton("\u8FD4\u56DE");
        backButton.addActionListener(arg0 -> {
        });
        backButton.setBounds(10, 148, 73, 25);
        contentPane.add(backButton);
    }

    public void getNickname(String nickname) {
        this.nickname = nickname;
    }
}

